package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import com.asiainfo.ysrman.doprocess.*;
import com.asiainfo.ysrman.Beans.*;
import java.util.*;
import java.text.*;

public final class Up2pSearch_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static java.util.Vector _jspx_dependants;

  static {
    _jspx_dependants = new java.util.Vector(1);
    _jspx_dependants.add("/uservalidate.jsp");
  }

  public java.util.List getDependants() {
    return _jspx_dependants;
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html; charset=GBK");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write('\r');
      out.write('\n');
	
	//??????
	if (session.getAttribute("userid") == null||session.getAttribute("userid").equals(""))
	{	
		//response.sendRedirect("index.jsp");
		out.println("<script language=\"javaScript\">parent.document.frames.top.window.location.href='index.jsp';</script>");
		return;
	}

      out.write("\r\n");
      out.write("\r\n");

    String whereStr = "";   
    

	String txtBDate = "";
	String txtEDate = "";
	String showBDate = "";
	String showEDate = "";
	int flag = 0;
	
	
	txtBDate = request.getParameter("txtDateBegin");
	txtEDate = request.getParameter("txtDateEnd");	
	
	SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd");
	if ( (txtBDate == null ||txtBDate.equals("")) && ( txtEDate == null ||txtEDate.equals("")) )
	{		
	   	txtBDate = "2007-06-01"; 
		txtEDate = sFormat.format(new Date( new Date().getTime()+1000*60*60*24));	
	   	flag = 1;//没有开始/结束日期
	}
	else if ( txtBDate != null && ( txtEDate == null || txtEDate.equals("") ))
	{
		showBDate = txtBDate;
		txtEDate = sFormat.format(new Date( new Date().getTime()+1000*60*60*24));
		flag = 2;//只有开始日期
	}
	else if ( (txtBDate == null || txtBDate.equals(""))&& txtEDate != null)
	{
		txtBDate = "2007-06-01";  
		//txtEDate = sFormat.format(new Date( new Date().getTime()));	 
		showEDate = txtEDate;
		flag = 3;//只有结束日期
	}
	else
	{
		showBDate = txtBDate;
		showEDate = txtEDate;
		flag = 0;//有开始结束日期  
	}
	String mStr = "";
	String dStr = "";
	
	mStr = txtBDate.substring(txtBDate.indexOf("-")+1,txtBDate.lastIndexOf("-"));
		 if (mStr.length()==1)
		 		mStr = "0" + mStr;
		 		
	dStr = txtBDate.substring(txtBDate.lastIndexOf("-")+1);
		if (dStr.length()==1)
		dStr = "0" + dStr;
			
	txtBDate = txtBDate.substring(0,txtBDate.indexOf("-")) + mStr + dStr + "000000";
	
	mStr = txtEDate.substring(txtEDate.indexOf("-")+1,txtEDate.lastIndexOf("-"));
		 if (mStr.length()==1)
		 		mStr = "0" + mStr;
		 		
	dStr = txtEDate.substring(txtEDate.lastIndexOf("-")+1);
		if (dStr.length()==1)
		dStr = "0" + dStr;
			
	txtEDate = txtEDate.substring(0,txtEDate.indexOf("-")) + mStr + dStr + "235959";	
	
	
	if (flag == 0)
		whereStr += " to_char(regdate,'YYYYMMDDHH24MISS')<=" + txtEDate + " and to_char(regdate,'YYYYMMDDHH24MISS')>="+txtBDate;
	if (flag == 1)
		whereStr += " ";
	if (flag == 2)
		whereStr += " to_char(regdate,'YYYYMMDDHH24MISS')>="+txtBDate;
	if (flag == 3)
		whereStr += " to_char(regdate,'YYYYMMDDHH24MISS')<=" + txtEDate ;		
	
 	
 	YsrProcess yprocess = new YsrProcess(); 	
 	
 	
 	int p1num = 0;
 	int p2num = 0;
 	int p3num = 0;
 	int p4num = 0;
 	
 	//System.out.println("wherestr="+whereStr);
	if (!whereStr.trim().equals("")) 
	{		
		String sql1 = "select count(DISTINCT(mobile)) as num from yl_ulog " 
					+ " where  mobile in (select mobile from yl_ulog where " + whereStr + " and pro_type=1)" 
					+ " and " + whereStr + " and pro_type=2";
		
		String sql2 = "select count(DISTINCT(mobile)) as num from yl_ulog " 
			+ " where  mobile in (select mobile from yl_ulog where " + whereStr + " and pro_type=1)" 
			+ " and " + whereStr + " and pro_type=3";
		
		String sql3 = "select count(DISTINCT(mobile)) as num from yl_ulog " 
			+ " where  mobile in (select mobile from yl_ulog where " + whereStr + " and pro_type=2)" 
			+ " and " + whereStr + " and pro_type=3";
		
		String sql4 = "select count(DISTINCT(mobile)) as num from yl_ulog where mobile in "
		    + " (select mobile from yl_ulog " 
			+ " where  mobile in (select mobile from yl_ulog where " + whereStr + " and pro_type=1)" 
			+ " and " + whereStr + " and pro_type=2)" 
			+ " and " + whereStr + " and pro_type=3";
		
		
		
		p1num = yprocess.getUp2Num(sql1);
		p2num = yprocess.getUp2Num(sql2);
		p3num = yprocess.getUp2Num(sql3);
		p4num = yprocess.getUp2Num(sql4);
	}
	
    if (showEDate.equals("")) showEDate = sFormat.format(new Date());

      out.write("\n");
      out.write("\r\n");
      out.write("<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n");
      out.write("<head>\r\n");
      out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />\r\n");
      out.write("<title>积分</title>\r\n");
      out.write("<link href=\"styles/styles.css\" rel=\"stylesheet\" type=\"text/css\" />\r\n");
      out.write("<script language=\"JavaScript\" src=\"script/date1.js\"></script>\r\n");
      out.write("<script language=\"JavaScript\" src=\"script/excel.js\"></script>\r\n");
      out.write("<style type=\"text/css\">\r\n");
      out.write("<!--\r\n");
      out.write("body {\r\n");
      out.write("\tbackground-color:#ffffff;\r\n");
      out.write("}\r\n");
      out.write("-->\r\n");
      out.write("</style></head>\r\n");
      out.write("\r\n");
      out.write("<body>\r\n");
      out.write("<IFRAME frameBorder=0 id=CalFrame marginHeight=0 marginWidth=0 noResize scrolling=no src=\"common/calendar.htm\" style=\"DISPLAY: none; HEIGHT: 194px; POSITION: absolute; WIDTH: 148px; Z-INDEX: 100\"></IFRAME>\r\n");
      out.write("\r\n");
      out.write("\t<table class=\"suoyin\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\r\n");
      out.write("      <tr>\r\n");
      out.write("        <td width=\"18%\">中奖管理&gt;&gt;产品统计</td>\r\n");
      out.write("        <td width=\"82%\"></td>\r\n");
      out.write("      </tr>\r\n");
      out.write("     </table>\r\n");
      out.write("    \r\n");
      out.write("\t<table class=\"xuanze\" width=\"95%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\r\n");
      out.write("      <tr>\r\n");
      out.write("        <td>\r\n");
      out.write("        <form id=\"Form1\" name=\"Form1\" method=\"post\" action=\"Up2pSearch.jsp\">\r\n");
      out.write("\t\t           \r\n");
      out.write("          <strong>选择时间：</strong>\r\n");
      out.write("\t          <input name=\"txtDateBegin\" type=\"text\" value=\"");
      out.print(showBDate );
      out.write("\" id=\"txtDateBegin\" style=\"width:88px;\" readonly class=\"inputr\">\r\n");
      out.write("\t\t\t\t\t\t\t\r\n");
      out.write("\t           <a onclick=\"event.cancelBubble=true;\" href=\"javascript:ShowCalendar(document.Form1.dimg1,document.Form1.txtDateBegin,null,0,330)\">\r\n");
      out.write("\t           <img src=images/calendar.gif width=\"21\" height=\"21\" border=0 align=absmiddle id=dimg1 alt=\"选择开始时间\">\r\n");
      out.write("\t           </a>\r\n");
      out.write("\t             至\r\n");
      out.write("\t           <input name=\"txtDateEnd\" type=\"text\" value=\"");
      out.print(showEDate );
      out.write("\" id=\"txtDateEnd\" style=\"width:88px;\" readonly class=\"inputr\">\r\n");
      out.write("\t               \r\n");
      out.write("\t           <a onclick=\"event.cancelBubble=true;\" href=\"javascript:ShowCalendar(document.Form1.dimg2,document.Form1.txtDateEnd,null,0,330)\">\r\n");
      out.write("\t           <img src=images/calendar.gif width=\"21\" height=\"21\" border=0 align=absmiddle id=dimg2 alt=\"选择结束时间\">\r\n");
      out.write("\t           </a>\r\n");
      out.write("        <label>\r\n");
      out.write("        <input type=\"submit\" name=\"Submit\" class=\"btn01\" value=\"确 定\" />\r\n");
      out.write("        \r\n");
      out.write("        &nbsp;&nbsp;\r\n");
      out.write("        \r\n");
      out.write("        <input type=\"button\" onclick=\"toExcel(outdata)\" value=\"保存数据\"  class=\"btn01\"> \r\n");
      out.write("        </label>\r\n");
      out.write("        </form>\r\n");
      out.write("\t  </td>\r\n");
      out.write("     </tr>\r\n");
      out.write("    </table>\r\n");
      out.write("\r\n");
      out.write("    <table id=\"outdata\" style=\"border:1px solid #CCCCCC;\" width=\"98%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\r\n");
      out.write("      \r\n");
      out.write("      <tr>\r\n");
      out.write("        <td>\r\n");
      out.write("          <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\r\n");
      out.write("            <tr>\r\n");
      out.write("              <td class=\"shujutittle\" width=\"25%\"><strong>瓶\\砖</strong></td>\r\n");
      out.write("              <td class=\"shujutittle\" width=\"25%\"><strong>瓶\\六连包</strong></td>\r\n");
      out.write("              <td class=\"shujutittle\" width=\"25%\"><strong>砖\\六连包</strong></td>   \r\n");
      out.write("              <td class=\"shujutittle\" width=\"25%\"><strong>瓶\\砖\\六连包</strong></td>              \r\n");
      out.write("               \r\n");
      out.write("            </tr>\r\n");
      out.write("        </table>\r\n");
      out.write("        </td>\r\n");
      out.write("      </tr>\r\n");
      out.write("      <tr>\r\n");
      out.write("        <td>        \r\n");
      out.write("           <table class=\"DoubleColorTable\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\r\n");
      out.write("           <tr>            \r\n");
      out.write("            <td align=left width=\"25%\"><b>");
      out.print(p1num );
      out.write("</b></td>\r\n");
      out.write("            <td align=left width=\"25%\"><b>");
      out.print(p2num );
      out.write("</b></td>\r\n");
      out.write("            <td align=left width=\"25%\"><b>");
      out.print(p3num );
      out.write("</b></td>\r\n");
      out.write("            <td align=left width=\"25%\"><b>");
      out.print(p4num );
      out.write("</b></td>\r\n");
      out.write("          \r\n");
      out.write("            </tr>           \r\n");
      out.write("        </table>\r\n");
      out.write("        </td>\r\n");
      out.write("      </tr>\r\n");
      out.write("      \r\n");
      out.write("    </table>   \r\n");
      out.write("\r\n");
      out.write("</body>\r\n");
      out.write("</html>\r\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
